﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Stamp_For_Africa_Version_2.Models;
using Stamp_For_Africa_Version_2.Repositories;

namespace Stamp_For_Africa_Version_2.Controllers
{
    public class CategoryController : Controller
    {
        //
        // GET: /Category/

        public ActionResult Index()
        {
          CategoryRepository categoryRepository = new CategoryRepository();
            return View(categoryRepository.FindAllCategories());
        }

      public ActionResult Create()
      {
        return View();
      }

      public ActionResult Details(Guid id)
      {
        CategoryRepository categoryRepository = new CategoryRepository();
        Category category = categoryRepository.GetCategory(id);

        return View(category);
      }

      [AcceptVerbs(HttpVerbs.Post)]
      public ActionResult Create(Category category)
      {
        Category nCategory = new Category();
        nCategory.Id = Guid.NewGuid();
        nCategory.DisplayName = category.DisplayName;
        CategoryRepository categoryRepository = new CategoryRepository();
        categoryRepository.Add(nCategory);
        categoryRepository.Save();
        return RedirectToAction("Details", category);
      }
    }
}
